/**this interface define the database operation function
 * fuzhou mydi corp.ltd @author lms 2017.12.07
 * last update by lms 2017.12.08
 */

package ms.core.db.mysql;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import ms.core.common.Page;
import ms.core.db.mysql.DbConfTool.DbType;

public interface IDbDrv{
	public boolean closeConnection();																	//to close connection
	public Connection getConnection();																	//get default connection by config name
	public String getDatabaseName();																	//get database name for default config name
	public DbType getDbType();																			//get database type
	public void startTran();																			//start transaction
	public void rollTran();																				//roll back transaction
	public void commitTran();																			//commit transaction

	public int executeSql(String sql);																	//run sql for effect rows
	public int executeSql(String sql, Object[] params);													//run sql with parameters
	public int executeSql(String sql, List<Object> params);												//run sql with parameters
	public int batchExecuteSql(String sql, List<Object[]> params);										//batch run sql with parameters

	public Object queryFieldValue(String sql, Class<?> cls, int col);									//to query field value with first row and column index
	public Object queryFieldValue(String sql, Class<?> cls, Object[] params, int col);					//to query field value with first row and column index
	public Object queryFieldValue(String sql, Class<?> cls, List<Object> params, int col);				//to query field value with first row and column index

	public <T>T queryForBean(String sql, Class<T> cls);													//query data for bean
	public <T>T queryForBean(String sql, Class<T> cls, Object[] params);								//query data for bean with parameters
	public <T>T queryForBean(String sql, Class<T> cls, List<Object> params);							//query data for bean with parameters

	public <T>List<T> queryForBeans(String sql, Class<T> cls);											//query data for beans
	public <T>List<T> queryForBeans(String sql, Class<T> cls, Object[] params);							//query data for beans with parameters
	public <T>List<T> queryForBeans(String sql, Class<T> cls, List<Object> params);						//query data for beans with parameters
	public <T>Page<T> queryForPage(QueryParam qp, Class<T> cls);										//query for page data
	
	//super interface function--------------------------------------------------------------------------

	public boolean tableExists(String table);															//to query if table exists	
	public int queryRecordCount(String table, Map<String, Object> cdt);									//to query record count by condition
	public int insertRecord(String table, Map<String, Object> values);									//to insert record
	public int insertRecord(String table, String operator, List<Map<String, Object>> values);			//to batch insert record
	public int modifyRecord(String table, Map<String, Object> values, Map<String, Object> cdt);			//to modify record by condition
	public int deleteRecord(String table, Map<String, Object> cdt);										//to delete record by condition
	public int deleteRecord(String table, long id);														//to delete record by reocrd id
	public <T>T getRecord(String table, long id, Class<T> cls);											//query data for bean
	public <T>T getRecord(String table, Map<String, Object> cdt, Class<T> cls);							//query data for bean
}
